package ru.spies.entities;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.REFRESH;
import static javax.persistence.FetchType.EAGER;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;


/**
 * The persistent class for the siteusers database table.
 * 
 */
@Entity
@Table(name="siteusers")
@NamedQuery(name="Siteuser.findAll", query="SELECT s FROM Siteuser s")
public class Siteuser implements Serializable, ITableClass {
	private static final long serialVersionUID = 1L;

	private Object paramForFindQuery=null;
	
	@Id
	@GeneratedValue
	@Column(unique=true, nullable=false)
	private Integer id;

	@Column(nullable=false, length=2147483647)
	private String password;

	@Column(nullable=false, length=2147483647)
	private String username;

	//bi-directional many-to-one association to Agent
	@OneToOne(fetch=EAGER, cascade = ALL)
	@JoinColumn(name="id_agent", nullable=false)
	private Agent agent;

	//bi-directional many-to-one association to Role
	@ManyToOne(fetch=EAGER, cascade = {REFRESH, MERGE})
	@JoinColumn(name="id_role", nullable=false)
	private Role role;
	

	public Siteuser() {
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public Agent getAgent() {
		return this.agent;
	}

	public void setAgent(Agent agent) {
		this.agent = agent;
	}

	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@Override
	public void setParamForFindQuery(Object param) {
		this.paramForFindQuery=(String) param;
	}

	@Override
	public Object getParamForFindQuery() {
		return paramForFindQuery;
	}

	@Override
	public ITableClass createThisObject() {
		return new Siteuser();
	}

	@Override
	public String getQueryForFind() {
		return "SELECT s FROM Siteuser s WHERE s.username= :param";
	}

}